"""自动生成HTML测试报告代码及修改时间"""
import unittest
from HTMLTestRunner import HTMLTestRunner
import time
#定义测试用例的目录为当前目录下的test_case目录
test_dir = './test_case'
suit = unittest.defaultTestLoader.discover(test_dir,pattern='test*.py')
if __name__ =="__main__":
    now_time = time.strftime("%Y-%m-%d %H_%M_%S")  # 显示新的Html文件及修改时间
    fp = open('./result.html' + now_time ,'wb')
    runner = HTMLTestRunner(stream=fp,
                            title="百度测试报告",
                            description="运行环境:windows 10 ，Chrome 浏览器")
    runner.run(suit)
fp.close()

#
# #整合
# import unittest
# from HTMLTestRunner import HTMLTestRunner
# import time
# import yagmail
# from HTMLTestRunner import HTMLTestRunner
# #把测试报告作为附件发送到指定邮箱
# def send_mail(report):
#     yag = yagmail.SMTP(user="18793637427@163.com",
#                        password="whc5201314",
#                        host="smtp.163.com")
#     subject = "主题:自动化测试报告"
#     contents = "正文，请查看附件"
#     yag.send("18793637427@163.com",subject,contents,report)
#     print("email has send out !")
#
# if __name__ =="__main__":
#     """定义测试用例的目录及为当前目录"""
#     test_dir = './test_case'
#     suit = unittest.defaultTestLoader.discover(test_dir,pattern='test*.py')
#     """获取当前时间和日期"""
#     now_time = time.strftime("%Y-%m-%d %H_%M_%S")  # 显示新的Html文件及修改时间
#     html_report = './result.html' + now_time +  "result.html"
#     fp = open(html_report + now_time, 'wb')
#     """调用HTMLTestRunner类，运行测试用例"""
#     runner = HTMLTestRunner(stream=fp,
#                             title="百度测试报告",
#                             description="运行环境:windows 10 ，Chrome 浏览器")
#     runner.run(suit)
# fp.close()
# send_mail(html_report)   # 发送测试报告


